using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class BuffDebuff : LoadableJSONObject{
	
	public List<TemporaryBonus> modifiers = new List<TemporaryBonus>{};	
	public bool active = true;

	public string buffDescription
	{
		get
		{	
			string desc = name + ": ";
			modifiers.ForEach((e) =>
				{
					desc += e.GetDescription() + ", ";
				}
			);
			desc = desc.TrimEnd(new char[]{' ',',','"'});
			
			return desc;
		}
	}
	
	public BuffDebuff()
	{
		
	}
	
	public override void Load(string json, string file)
	{
		fileName = file;
		if(json != null)
		{
			Dictionary<string,string> data = (MiniJSON.Json.Deserialize(json) as Dictionary<string,object>).ToDSS();
			
			name = data["name"];
			description = data["description"];
			active = bool.Parse(data["active"]);
			
			modifiers = new List<TemporaryBonus>();
			
			foreach(object tb in MiniJSON.Json.Deserialize(data["modifiers"]) as List<object>)
			{
				TemporaryBonus tbo = new TemporaryBonus();
				tbo.LoadFromJSON(tb.ToString(), this);
				modifiers.Add(tbo);
			}
		}
	}
	
	public override string ToJSON()
	{
		Dictionary<string,string> data = new Dictionary<string, string>();
		data.Add("name", name);
		data.Add("description", description);
		data.Add("modifiers", modifiers.ToJSON());
		data.Add("active", active.ToString());
		return MiniJSON.Json.Serialize(data);
	}
	
	public BuffDebuff DeepCopy()
	{
		BuffDebuff a = new BuffDebuff();
		a.Load(ToJSON(), fileName);
		return a;
	}
}
